<template>
  <div class="home">
    <!--<mt-header fixed title="我的证书">
      <router-link to="/" slot="left">
        <mt-button icon="back"></mt-button>
      </router-link>
    </mt-header>-->

    <div class="content-box">
      <div class="padding-lr-32">

        <ul class="normal-list" v-if="id === 'rySafety'">
          <li v-for="(item,index) in list" :key="index">  <!--安全生产-->
            <router-link :to="{path:'/detail-safety',query:item}">
              <h3 class="title3  margin-bottom-10">{{item.safetyTypeName}}</h3>
              <div class="flex justify-between">
                <div class="normal-list-item" style="width: 60%">
                  <p class="normal-list-item-label margin-bottom-10">证书编号</p>
                  <p class="normal-list-item-val ">{{item.safetyNo}}</p>
                </div>
                <div class="normal-list-item" style="width: 40%">
                  <p class="normal-list-item-label margin-bottom-10">有效期</p>
                  <p class="normal-list-item-val">{{item.safetyEdate}}</p>
                </div>
              </div>
            </router-link>
          </li>
        </ul>

        <ul class="normal-list" v-if="id === 'rySpecial'">
          <li v-for="(item,index) in list" :key="index"> <!--特种证书查询-->
            <router-link :to="{path:'/detail-special',query:item}">
              <h3 class="title3  margin-bottom-10">{{item.specialTypeName}}</h3>
              <div class="flex justify-between">
                <div class="normal-list-item" style="width: 60%">
                  <p class="normal-list-item-label margin-bottom-10">证书编号</p>
                  <p class="normal-list-item-val ">{{item.specialNo}}</p>
                </div>
                <div class="normal-list-item" style="width: 40%">
                  <p class="normal-list-item-label margin-bottom-10">有效期</p>
                  <p class="normal-list-item-val">{{item.specialEdate}}</p>
                </div>
              </div>
            </router-link>
          </li>
        </ul>

        <ul class="normal-list" v-if="id === 'ryReg'">
          <li v-for="(item,index) in list" :key="index"> <!--注册证书-->
            <router-link :to="{path:regPath,query:item}">
              <h3 class="title3  margin-bottom-10">{{item.ryRegTypeName}}</h3>
              <div class="flex justify-between">
                <div class="normal-list-item" style="width: 60%">
                  <p class="normal-list-item-label margin-bottom-10">证书编号</p>
                  <p class="normal-list-item-val ">{{item.certRegNo}}</p>
                </div>
                <div class="normal-list-item" style="width: 40%">
                  <p class="normal-list-item-label margin-bottom-10">有效期</p>
                  <p class="normal-list-item-val">{{item.certEdate}}</p>
                </div>
              </div>
            </router-link>
          </li>
        </ul>

        <div class="no-data" v-if="list.length===0">
          <p>暂无此类证书</p>
        </div>

      </div>
    </div>

  </div>
</template>

<script>
  import { Indicator } from 'mint-ui';
export default {
  name: 'Home',
  data() {
    return {
      id:'',
      regPath:'/detail-reg',
      papersnumber:'',
      list: new Array()
    }
  },
  beforeRouteEnter(to, from, next) {
    let pages = [
      'detail-safety','detail-reg','detail-reg0204','detail-special'
    ];
    if(pages.includes(from.name)){
      to.meta.isBack=true;
    }
    next();
  },

  activated() {
    if(!this.$route.meta.isBack){
      this.loadData()
    }
    this.$route.meta.isBack=false

  },
  mounted() {
    this.loadData()
  },
  methods: {

    loadData(){
      let { papersnumber , id  , type } = this.$route.query;
      this.id = id || '';
      this.papersnumber  = papersnumber;
      //console.log(papersnumber);
      Indicator.open('加载中...');
      if(this.id === 'rySafety'){
        this.GetListSafety();
      }else if(this.id === 'rySpecial'){
        this.GetListSpecial();
      }else if(this.id === 'ryReg'){
        this.GetListReg(type);
      }
    },


    GetListSafety:function (data) {  //安全生产
      let date = new Date().getTime().toString();
      let sign = this.$md5('rySafety' + date);
      let param = {
        from: '3',
        key: 'a98dc7f655df4966a5f0dfa6057c8475',
        sign: sign,
        requestTime: date,
        //ryCard:'362222196912013526',
        ryCard:this.papersnumber
      };
      this.$api.post('/jimp/link.do', {
        param : JSON.stringify(param)
      }, response => {
        console.log(response);
        if(response.status==='200' && (response.data.result || response.data.code ==="200")){
          this.list = response.data.data;
        }else {
          this.list = [];
        }
        Indicator.close();
      });
    },

    GetListSpecial:function (data) {  //特种证书查询
      let date = new Date().getTime().toString();
      let sign = this.$md5('rySpecial' + date);
      let param = {
        from: '3',
        key: '534d996466b741b9827404104f2ccfcd',
        sign: sign,
        requestTime: date,
        //ryCard:'362531198810042416',
        ryCard:this.papersnumber
      };
      this.$api.post('/jimp/link.do', {
        param : JSON.stringify(param)
      }, response => {
        console.log(response);
        if(response.status==='200' && (response.data.result || response.data.code ==="200")){
          this.list = response.data.data;
        }else {
          this.list = [];
        }
        Indicator.close();
      });
    },

    GetListReg:function (type) {  //省管注册
      const arr = [
        {type:'RY_REG_0014',ryCard:'36242819661227001X',to:'/detail-reg'},//注册建造
        {type:'RY_REG_0002',ryCard:'362428196103280017',to:'/detail-reg0204'},//注册建筑
        {type:'RY_REG_0004',ryCard:'362329199201010330',to:'/detail-reg0204'},//结构
        {type:'RY_REG_0016',ryCard:'36242719670713003X',to:'/detail-reg'}//临时建造
      ];
      let item = arr.filter(item=>item.type === type)[0];
      this.regPath = item.to;
      let date = new Date().getTime().toString();
      let sign = this.$md5('ryReg' + date);
      let param = {
        from: '3',
        key: '8a4ba95885304f72b4ea77030d2a8a74',
        sign: sign,
        requestTime: date,
        //ryCard:item.ryCard,
        ryCard:this.papersnumber,
        qyRegType: type
      };
      this.$api.post('/jimp/link.do', {
        param : JSON.stringify(param)
      }, response => {
        console.log(response);
        if(response.status===200 && (response.data.result || response.data.code ==="200")){
          this.list = response.data.data;
        }else {
          this.list = [];
        }
        Indicator.close();
      });
    }


  }
}
</script>
<style lang="less" scoped>


</style>
